from django_filters.rest_framework import FilterSet
from django_filters.filters import *
from .models import *


class HawkeyeFilterSet(FilterSet):
    host = CharFilter(field_name="host__address", lookup_expr="contains")
    title = CharFilter(lookup_expr="contains")
    message = CharFilter(lookup_expr="contains")
    analysis = CharFilter(lookup_expr="contains")
    remark = CharFilter(lookup_expr="contains")
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = Hawkeye
        fields = [
            "host",
            "title",
            "message",
            "analysis",
            "status",
            "remark",
            "start_time",
            "end_time",
        ]


class HawkeyeJobFilterSet(FilterSet):
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = HawkeyeJob
        fields = ["name", "status", "start_time", "end_time"]
